package com.study.experiment05.servlet;

import com.study.experiment05.bean.UserChecker;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author WS
 */
@WebServlet(name = "UserLoginServlet", urlPatterns = "/experiment05/userLogin")
public class UserLoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String username = request.getParameter("username");
        String passwd = request.getParameter("pwd");
        UserChecker checker = new UserChecker(username, passwd);
        if (checker.check()) {
            out.println("<p>welcome," + username + "</p>");
        } else {
            out.println("<p>username not exist or password is wrong</p>");
        }
        out.flush();
        out.close();

    }
}
